package com.dgw.springbootrabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: spring-boot-rabbitmq
 * @description:
 * @author: Mr.Dai
 * @create: 2020-02-20 23:08
 **/
@Configuration
public class RpcConfig {

    public final static String RPC_EXCHANGE_NAME="my.rpc";
    public final static String RPC_QUEUE_NAME="rpc.requests";
    @Bean
    public Queue queue() {
        // 指定交换队列名称
        return new Queue(RPC_QUEUE_NAME);
    }

    @Bean
    public DirectExchange exchange() {
        return new DirectExchange(RPC_EXCHANGE_NAME);
    }

    @Bean
    public Binding binding(DirectExchange exchange,
                           Queue queue) {
        return BindingBuilder.bind(queue)
                .to(exchange)
                .with("rpc");//指定路由路径
    }
}
